﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
#if WINDOWS_PHONE
using Microsoft.Xna.Framework.Input.Touch;
#endif
#if WINDOWS
using Microsoft.Xna.Framework.Storage;
#endif
using Microsoft.Xna.Framework.Media;
using Neat;
using Neat.MenuSystem;
using Neat.EasyMenus;
using Neat.GUI;
using Neat.Mathematics;
using Neat.Graphics;
using System.IO;

namespace RiverRaidX
{
    public partial class RiverRaidGame : Screen
    {
        public RiverRaidGame(NeatGame Game)
            : base(Game)
        {
        }

        #region FIELDS
        enum Items
        {
            Fuel,
            Ship,
            Heli,
            House,
            Tree,
            Bridge,
            Jet
        }

        class Entity
        {
            public string TextureName;
            public Vector2 Position;
            public Vector2 Size;
            public bool NoClip;
            public float Speed;
            public bool Flip;
            public int WakeUpDistance;
            public Items ItemType;
            public int ScorePoints=0;
            public bool Immortal = false;
            public Polygon Mesh;
            public float ZombieTimer = 0;
            public string ExplodeSound = "explosion";
        }

        LineBrush lb;

        float stillPlayerWidth;
        float movingPlayerWidth;

        int _score;
        int score { get { return _score; } set { if (_score != value) { _score = value; scoreValue.Caption = _score.ToString(); scoreValue.Reset(); } } }
        float _fuel;
        float fuel { get { return _fuel; } set { _fuel = value > maxFuel ? maxFuel : value; UpdateGauge(); } }
        int _lives;
        int lives { get { return _lives; } set { if (_lives != value) { _lives = value; livesValue.Caption = _lives.ToString(); livesValue.Reset(); } } }
        float rocketY;

        float yOffset;
        float ySpeed;
        float rocketSpeed;
       
        bool rocketLaunched = false;
        float xForce;
#if KINECT
        float dampCoEf = 0.9f;
#else
        float dampCoEf = 0.97f;
#endif
        float pxVelCoef = 1f;
        float pxVel = 0f;
        float speedBoostRate = 1.7f;
        float maxFuel = 1000;
        float explosionLife = 10.0f;
        int initLives = 2;
        float fuelUseRate;
        Vector2 collisionThreshold = new Vector2(1);
        Vector2 originalGameSize = new Vector2(1280, 720);
        Vector2 scale;
        Vector2 rocketSize;
        Vector2 pPos, pSize;
        Vector2 ar;
        Polygon playerMesh;

        List<Vector2> outerWalls;
        List<Vector2> innerWalls;
        List<Entity> entities;
        List<Entity> deadEntities;
        List<Polygon> walls;
        List<float> checkpoints;
        List<string> levelPaths;
        List<Color> grassColors;

        int lastLoadedLevel;
        int currentLevel, startingLevel;

        Label scoreText, livesText;
        FancyLabel scoreValue, livesValue;
        Image fuelBg;
        Box fuelArrow;
        
        Color grassColor;

        int blinkFrame = 0;
        int blinkTime = 30;
        int blinkPeriod = 2;

        int deathTime = 40;
        int deathFrame = 0;
        bool toggleBlink = false;

        int extraLifeScore = 20000;
        Vector4 siren = Color.Green.ToVector4();

        public bool NoPlayer = true;
        bool _noPostFx = false;
        public bool NoPostFx
        {
            get
            {
                return _noPostFx;
            }
            set
            {
                //if (game != null && game.Console != null)
                //    game.Console.Run("dv rr_effects " + (!value).ToString());
                _noPostFx = value;
            }
        }

        public Vector2 rocketPos, lastRocketPos;
        SoundEffectInstance engineInstance, engineStartInstance, fuelInstance, staticInstance;
        RenderTarget2D target;

        public enum GameMessages
        {
            MoveLeft,
            MoveRight,
            SpeedUp,
            SlowDown,
            ShootRocket
        }

        enum GameStates
        {
            DeathAnimation = 1,
            StartAnimation = -1,
            Game = 0
        }
        GameStates state;

        public HashSet<GameMessages> Messages = new HashSet<GameMessages>();

        Vector2 boostVec = Vector2.Zero;
        #endregion
    }
}
